package br.com.fogas.utils.validacao;

import android.view.View;
import android.view.View.OnFocusChangeListener;
import android.widget.EditText;

public class PreenchidoQtdCaracteres extends ValidacaoResponsability {
	
	private int quantity;

	public PreenchidoQtdCaracteres(final View view, final String message, final int quantity) {
		super(view, message);
		this.quantity = quantity;
		EditText editText = (EditText) view;
		editText.setOnFocusChangeListener(new OnFocusChangeListener() {
			
			@Override
			public void onFocusChange(View view, boolean hasFocus) {
				if(!hasFocus) {
					Validacao.validateQuantityCaracters(view, message, quantity, true, false);
				}
			}
		});
	}

	@Override
	public boolean campoValido() {
		boolean campoAtual = Validacao.validateQuantityCaracters(view, message, quantity, true, true);
		
		if(proximo != null) {
			boolean proximoCampo = proximo.campoValido();
			
			if(campoAtual && proximoCampo) {
				return true;
			}else if(!campoAtual) {
				return false;
			} else if(!proximoCampo) {
				return false;
			}
		}
		
		return campoAtual;
	}
}